/**
 * Created by lixin on 2019-09-17
 */


/***
 * 处理成功响应
 * */
exports.success = (ctx, res = null, msg = '请求成功') => {

    ctx.body = {
        code: '0000',
        data: res,
        msg
    };
    ctx.status = 200;
};

/**
 * 处理失败响应
 * */

exports.error = (ctx, res = null, code = '0001', msg = '请求失败') => {
    ctx.body = {
        code: code,
        data: res,
        msg
    };
    ctx.status = 200;
};
/**
 * 生产唯一编码
 * */
// 生成唯一-随机token
exports.guid = () => {
    const S4 = () => (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1);
    return S4() + S4() + '-' + S4() + '-' + S4() + '-' + S4() + '-' + S4() + S4() + S4();
};
/**
 * 错误码
 * */
exports.SYSTEM_ERROR = {
    code: '0002',
    msg: '系统异常'
};

exports.PARAMS_ERROR = {
    code: '0003',
    msg: '参数错误'
}
